/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package horsechess.packet;

import horsechess.util.Point;

/**
 *
 * @author Administrator
 */
public class PlayerPacket {

    String playerName;
    int diceValue1 = 0;
    int diceValue2 = 0;
    int score = 0;
    int numberOfChessman = 4;
    String room = null;
    int posOfPlayer;//Position of player on the board
    String message = "";

    public PlayerPacket(String msg) {
        //System.out.println("Split message: " + msg);
        String[] strs = msg.split("#");

        try {
            room = strs[1];
            playerName = strs[2];
            posOfPlayer = Integer.parseInt(strs[3]);
            diceValue1 = Integer.parseInt(strs[4]);
            score = Integer.parseInt(strs[5]);
            numberOfChessman = Integer.parseInt(strs[6]);
            diceValue2 = Integer.parseInt(strs[7]);


        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("got player info!!");
        } catch (NumberFormatException nfe) {
            System.out.println("Nothing change");
        }
    }

    public PlayerPacket(String playerName, int diceValue1, int diceValue2, int score) {
        this.playerName = playerName;
        this.diceValue1 = diceValue1;
        this.diceValue2 = diceValue2;
        this.score = score;
    }

    public PlayerPacket(String playerName, String room) {
        this.playerName = playerName;
        this.room = room;
        diceValue1 = 0;
        diceValue2 = 0;
        score = 0;
    }

    public PlayerPacket(String playerName, int diceValue1, int diceValue2) {
        this.playerName = playerName;
        this.diceValue1 = diceValue1;
        this.diceValue2 = diceValue2;
    }

    public int getNumberOfChessman() {
        return numberOfChessman;
    }

  

    public void setNumberOfChessman(int numberOfChessman) {
        this.numberOfChessman = numberOfChessman;
    }

   

    public String getPlayerName() {
        return playerName;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    public int getDiceValue1() {
        return diceValue1;
    }

    public void setDiceValue1(int diceValue1) {
        this.diceValue1 = diceValue1;
    }

    public int getDiceValue2() {
        return diceValue2;
    }

    public void setDiceValue2(int diceValue2) {
        this.diceValue2 = diceValue2;
    }

    public void setPlayerName(String playerName) {
        this.playerName = playerName;
    }

    public int getPosOfPlayer() {
        return posOfPlayer;
    }

    public void setPosOfPlayer(int posOfPlayer) {
        this.posOfPlayer = posOfPlayer;
    }

    public String getRoom() {
        return room;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setRoom(String room) {
        this.room = room;
    }

    public String getMessage() {
        return message;
    }

    @Override
    /**
     * 1: room
     * 2: playerName
     * 3: posOfPlayer
     * 4: value of dice
     * 5: score of this player
     * 6: Number of chessman
     */
    public String toString() {
        String position = "null";
      
        String message = "@Player#" + room + "#" + playerName + "#" + posOfPlayer + "#" + diceValue1 + "#" + score + "#" + numberOfChessman + "#"
                + diceValue2;


        //System.out.println("ToString message: "+message);
        return message;
    }

    public String toRoom() {
        return message = "@Player#" + room + "#" + playerName + "#" + posOfPlayer + "#" + diceValue1 + "#" + score + "#" + numberOfChessman + "#" + diceValue2;
    }

    public String chat() {
        return "@Chat#" + playerName + ":" + message;
    }

    public String room() {
        return "@Room-" + room + "-" + playerName;
    }


}
